package com.huayecai.controller;

import com.huayecai.pojo.Dept;
import com.huayecai.pojo.Result;
import com.huayecai.service.DeptService;
import com.huayecai.service.impl.DeptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping(value = "/depts", method = RequestMethod.GET)
    public Result list(String name){
        Result result = new Result();
        List<Dept> depts = deptService.findAll();
        return Result.success(depts);
    }

    @DeleteMapping("/depts")
    public Result deleteById(Integer id){
        deptService.deleteById(id);
        return Result.success();
    }

    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("/depts/{id}")
    public Result getInfo(@PathVariable Integer id){
        return Result.success(deptService.getById(id));
    }

    @PutMapping("/depts")
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
